package com.fastCms.manager.bim.controller;


import com.fastCms.business.bim.manage.DeviceGroupManageService;
import com.fastCms.business.bim.pojo.po.DeviceGroupAddPO;
import com.fastCms.business.bim.pojo.po.DeviceGroupPO;
import com.fastCms.business.bim.pojo.po.DeviceGroupRelPO;
import com.fastCms.business.bim.pojo.vo.DeviceGroupVO;
import com.fastCms.business.bim.pojo.vo.DeviceInfoVO;
import com.fastCms.business.frame.pojo.PageParam;
import com.fastCms.business.frame.response.ApiResponse;
import com.fastCms.business.frame.response.ResponseUtil;
import com.fastCms.manager.frame.annotation.UserAccess;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 设备组 前端控制器
 * </p>
 *
 * @author liusq
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/deviceGroup")
@Api(value = "DeviceGroupController", tags = "后端-设备组相关")
@UserAccess
public class DeviceGroupController {

    @Autowired
    private DeviceGroupManageService deviceGroupManageServiceImpl;

    @ApiOperation(value = "列表", notes = "")
    @PostMapping("/list")
    public ApiResponse<PageInfo<DeviceGroupVO>> list(@RequestBody PageParam<DeviceGroupPO> pageParam) {
        PageInfo<DeviceGroupVO> result = deviceGroupManageServiceImpl.list(pageParam);
        return ResponseUtil.success(result);
    }

    @ApiOperation(value = "新增或修改", notes = "")
    @PostMapping("/saveOrUpdate")
    public ApiResponse<Boolean> saveOrUpdate(@RequestBody DeviceGroupAddPO groupAddPO) {
        ApiResponse<Boolean> detail = deviceGroupManageServiceImpl.saveOrUpdate(groupAddPO);
        return detail;
    }

    @ApiOperation(value = "删除关联的某个设备", notes = "")
    @GetMapping("/delRelDevice/{groupId}/{deviceId}")
    public ApiResponse<Boolean> delRelDevice(@PathVariable Integer groupId, @PathVariable Integer deviceId) {
        ApiResponse<Boolean> result = deviceGroupManageServiceImpl.delRelDevice(groupId, deviceId);
        return result;
    }

    @ApiOperation(value = "删除组", notes = "")
    @GetMapping("/delete/{groupId}")
    public ApiResponse<Boolean> delete(@PathVariable Integer groupId) {
        ApiResponse<Boolean> result = deviceGroupManageServiceImpl.delete(groupId);
        return result;
    }

    @ApiOperation(value = "关联设备", notes = "")
    @PostMapping("/relDevice")
    public ApiResponse<Boolean> relDevice(@RequestBody DeviceGroupRelPO deviceGroupRelPO) {
        ApiResponse<Boolean> detail = deviceGroupManageServiceImpl.relDevice(deviceGroupRelPO);
        return detail;
    }

    @ApiOperation(value = "获取组内已关联设备", notes = "")
    @PostMapping("/getRelDevices/{groupId}")
    public ApiResponse<List<DeviceInfoVO>> getRelDevices(@PathVariable Integer groupId) {
        ApiResponse<List<DeviceInfoVO>> getRels = deviceGroupManageServiceImpl.getRelDevices(groupId);
        return getRels;
    }
}

